package makabakaquestionnaire.zutsoftware.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    /**
     * 测试分组
     * @return
     */
    @Bean
    public Docket docket1(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("其他");
    }
    @Bean
    public Docket docket(Environment environment){
        /**
         * 提取配置的环境，用于判断是否开启swagger-ui
         */
        Profiles profiles=Profiles.of("dev","test");
        boolean flag=environment.acceptsProfiles(profiles);
        /**
         *                 .select()
         *                 .apis(RequestHandlerSelectors.any())
         *                 .build();
         *                 RequestHandlerSelectors开启扫描的包
         */
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                //.enable(false)    //不开启swagger扫描接口
                .enable(flag)
                .groupName("问卷")
                .select()
                .apis(RequestHandlerSelectors.basePackage("makabakaquestionnaire.zutsoftware.controller"))
                .build();
    }
    private ApiInfo apiInfo(){
        Contact contact=new Contact("wjf","http://139.196.12.141:8282/","572812703@qq.com");
        return new ApiInfo(
                "通用问卷项目api接口文档",
                 "致力于方便问卷管理创建填写",
                "1.0",
                "http://139.196.12.141:8282/",
                contact,
                "Apache",
                "http://www.apache.org.licenses/LICENSE-2.0",
                new ArrayList()
                );

    }
}
